<?php 
require('src/OrdenCompra.class.php');
$id   = (isset($_GET['id'])) ? $_GET['id']:0;
$proId      = 0;
$proNombre   = "";
$odcId      = $id;
$odcCod     = "";
        
if($id!=0){    
    $obj    = new OrdenCompra();
    $res    = $obj->getConsulta($id);
    if( $row = mysql_fetch_array( $res ) ){
        $proId      = $row["pro_id"];
        $proNombre  = $row["pro_cirif"].' / '.$row["pro_razonsocial"];        
        $odcId      = $row["odc_id"];
	$odcCod     = $row["odc_codigo"];
    }
}

?>
<script type="text/javascript">
var id 		= <?php echo $id; ?>;
var odcId       = <?php echo $odcId; ?>;
var iocArray    = null;
$(document).ready(function(){

    jQuery("#formID").validationEngine();

    if(id==0){
        $("#prove").autocomplete({
            source: "src/ordencompra.php?modo="+5,
            minLength: 2,
            select: function(event, ui) {
                     $("#proId").val(ui.item.id);
            }
        });
    }else{
        $('#prove').attr('disabled',true); 
    }
    
    $('#targetA').click(function() {
         if($('#formID').validationEngine('validate')){
             var proId = $('#proId').attr('value');
             $("#result-search").load('mOrdenCompra.php?id='+id+"&proId="+proId+"&odcId="+odcId,  {proId: proId}, function(){
                $.ajax({
                    url: 'src/ordencompra.php?modo=6',
                    data: "submit=&proId="+proId+"&odcId="+odcId,
                    dataType: "json",
                    success: function(data) {
                         var pro = (typeof data.d) == 'string' ? eval('(' + data.d + ')') :  data;
                         $("#lblRif").html(pro[0].cirif);
                         $("#lblRazonS").html(pro[0].razonS);
                         $("#lblDireccion").html(pro[0].direcF);
                         $("#lblTelefono").html(pro[0].tlfOfi); 
                         if(id!=0){
                             iocArray = pro[1];
                             agregarRow();
                         }
                         
                    }
                });
             });
            
         }
    });
});

</script>
<h1></h1>

<div class="z-form content-search" >
    <span class="title"> B&uacute;squeda </span>    
    <form id="formID">
        <div class="search">
            <label for="prove"><span class="required">*</span>Proveedor </label>        
            <input type="text" id="prove" name="prove" class="validate[required] text-input meddium" value="<?php echo $proNombre ; ?>" />
            <span class="text-small">M&iacute;nimo 2 caracteres para la b&uacute;squeda.</span>
            <input type='hidden' id="proId"  name="proId" value='<?php echo $proId; ?>'  />            
        </div>
        <a title="Aplicar B&uacute;squeda" id="targetA" > <img src="public/images/shared/search.gif"  align="middle"/> Buscar</a>            
    </form>
</div>

<div id="result-search">
</div>


<?php //include('includes/footer.php'); ?>
